package com.ncs.stm.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import com.ncs.stm.R;

/**
 * Created by wensheng on 14-9-13.
 */
public class ImageAdapter extends BaseAdapter{
    private Context context;
    private int[] images;

    public ImageAdapter(Context context) {
        this.context = context;
        images = getImages();
    }

    @Override
    public int getCount() {
        return images.length;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ImageView imageView;
        if(view == null){
            imageView = new ImageView(context);
            imageView.setLayoutParams(new GridView.LayoutParams(200,200));
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        }else{
            imageView = (ImageView)view;
        }
        imageView.setImageResource(images[i]);
        return imageView;
    }

    private int[] getImages(){
        return  new int[]{
                R.drawable.img_1,R.drawable.img_2,R.drawable.img_3,
                R.drawable.img_4,R.drawable.img_5,R.drawable.img_6,
                R.drawable.img_7,R.drawable.img_8,R.drawable.img_9};

    }
}
